package com.slipper.login;

import com.slipper.PaasContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class LoginFactory {
    private static final Logger logger = LoggerFactory.getLogger(LoginFactory.class);

    public static Object login(String type, Map<String, Object> paramMap) {
        for (ILoginStrategy strategy : PaasContext.getBeans(ILoginStrategy.class).values()) {
            if (strategy.supports(type)) {
                return strategy.login(paramMap);
            }
        }

        logger.error("不支持的登录策略【{}】。", type);
        throw new RuntimeException("不支持的登录策略【" + type + "】。");
    }
}
